#/bin/sh

dsrc="../rfcs/*.txt"
dout="./out"
fout=
fext=xhtml
fbeg="./head.txt"
fmid="./body.txt"
fend="./tail.txt"

for f in $(ls ${dsrc});do

	echo -en "\e[31m converting file $f ...\e[0m"

	fout=${dout}/${f##*/}.${fext}

	cat ${fbeg}>$fout
	
	echo "<h1>${fout##*/}</h1>">>$fout
	echo "<title>${fout##*/}</title>">>$fout

	cat ${fmid}>>$fout

	#sed -s "s/[\&\f]/\&amp;/g" $f|sed -s "s/</\&lt;/g"|sed -s "s/>/\&gt;/g"|sed -s "s/ /\&nbsp;/g"|sed -s "s/\t/\&nbsp;\&nbsp;\&nbsp;\&nbsp;/g"|sed -s "s/$/<br\/>/g">>$fout
	sed -s "s/[\&\f]/\&amp;/g" $f|sed -s "s/</\&lt;/g"|sed -s "s/>/\&gt;/g">>$fout

	cat ${fend}>>$fout

	echo -e "\e[32m done\e[0m"

done